var PeopleMedia = PeopleMedia || {};
PeopleMedia.Profile = new function () {
    this.Actions = {};
    this.UserName = null;
    this.EncodedMemberId = null;
    this.GenderId = 0;
    this.HasMainPhoto = false;
    this.PhotosLoaded = false;
    this.HistoryLoaded = false;
    this.HimHerText = 'them';
    this.SendMessageUPN = 8;
    this.SendCommentUPN = 65;
    this.IsSelfProfile = false;
    this.IsTodaysMatch = false;
    this.FlirtSent = false;
    this.TodaysMatchCurrent = 1;
    this.MaximumMessageLength = 3000;
    this.CommonalityMessage = '';
    this.IsCommonalityEnabled = '';
    this.Photos = [];
    this.FeatureName = { Profile: 'profile', ProfilePhotoZoom: 'profilephotozoom', ProfilePhotoTab: 'profilephototab', TodaysMatch: 'todaysmatchesprofile' };
    this.ReportConcernPopup = function (encMemberId, username, isTodaysMatches) {
        try {
            PeopleMedia.Popups.ReportConcern(encMemberId, username, null, null, null, isTodaysMatches);
            PeopleMedia.Profile.ReloadAds();
        } catch (ex) {
            PeopleMedia.Logger.LogExceptionWithDetail(ex, { method: "PeopleMedia.Profile.ReportConcern" });
        }
    };
    this.ShareProfilePopup = function (encMemberId, username) {
        try {
            PeopleMedia.Popups.ShareProfile(encMemberId, username);
            PeopleMedia.Profile.ReloadAds();
        } catch (ex) {
            PeopleMedia.Logger.LogExceptionWithDetail(ex, { method: "PeopleMedia.Profile.ShareProfilePopup" });
        }
    };
    this.sendFlirt = function () {
        try {
            if (!PeopleMedia.Profile.IsSelfProfile && !PeopleMedia.Profile.FlirtSent) {
                $jq('#SendFlirtButtonLink').addClass('buttonunavailable').attr('title', 'Flirt Sent');
                PeopleMedia.Profile.FlirtSent = true;
                var url = PeopleMedia.Profile.Actions.SendFlirtUrl;
                $jq.ajax({
                    type: 'POST',
                    url: url,
                    data: { EncodedMemberId: PeopleMedia.Profile.EncodedMemberId, FeatureName: PeopleMedia.Profile.FeatureName.Profile },
                    success: function (response) {
                        if (response.status == "Success") {
                            if (response.data && response.data.IsUploadPhotoCTA) {
                                location.href = '/v3/Features/FlirtSent/?profile=' + PeopleMedia.Profile.EncodedMemberId + '&Flirt=1';
                            }
                            else {
                                PeopleMedia.Profile.flirtSentPopup();
                            }
                        } else {
                            PeopleMedia.Profile.handleError(response);
                        }
                    }
                });
            }
        } catch (ex) {
            PeopleMedia.Logger.LogExceptionWithDetail(ex, { method: "PeopleMedia.Profile.sendFlirt" });
        }
    };
    this.flirtSentPopup = function (fromBday) {
        try {
            var fromPage = location.search + '&from=Profile';
            if (!PeopleMedia.Profile.IsSelfProfile) {
                PeopleMedia.Popups.FlirtSent(PeopleMedia.Profile.EncodedMemberId, PeopleMedia.Profile.UserName, PeopleMedia.Profile.GenderId, PeopleMedia.Profile.HasMainPhoto, fromPage, PeopleMedia.Profile.FeatureName.Profile, PeopleMedia.Profile.SendMessageUPN, fromBday);
                PeopleMedia.Profile.ReloadAds();
            }
        } catch (ex) {
            PeopleMedia.Logger.LogExceptionWithDetail(ex, { method: "PeopleMedia.Profile.flirtSentPopup" });
        }
    };
    this.loadPhotos = function (mediaId) {
      
        if ($jq.bbq.getState('tab') !== 'photos') {
            $jq(window).unbind('hashchange');
            $jq.bbq.pushState({ tab: 'photos' }, 2);
            $jq(window).bind('hashchange', PeopleMedia.Profile.hashchange);
        }
        PeopleMedia.Profile.showTabPhotos();
        if (!PeopleMedia.Profile.PhotosLoaded) {
            $jq.ajax({
                type: 'POST',
                url: PeopleMedia.Profile.Actions.GetPhotosUrl,
                data: { EncodedMemberId: PeopleMedia.Profile.EncodedMemberId },
                success: function (response) {
                    PeopleMedia.Profile.ReloadAds();
                    if (response.status == "Success") {
                        $jq('#photoscontentarea').empty().html(response.html);
                        if (!PeopleMedia.Profile.IsSelfProfile) {
                            if (PeopleMedia.Profile.IsTodaysMatch) {
                                $jq('#photoscontentarea').find('#NoPhotosLink').attr('href', '/v3/features/oneclickflirt?&Flirt=7&Profile=' + PeopleMedia.Profile.EncodedMemberId + '&back=TodaysMatches&hash=tab=photos&featureName=' + PeopleMedia.Profile.FeatureName.TodaysMatch + '&backparam=' + PeopleMedia.Profile.TodaysMatchCurrent);
                            }
                            else {
                                $jq('#photoscontentarea').find('#NoPhotosLink').attr('href', '/v3/features/oneclickflirt?&Flirt=7&Profile=' + PeopleMedia.Profile.EncodedMemberId + '&back=Profile&hash=tab=photos&featureName=' + PeopleMedia.Profile.FeatureName.Profile + '&backparam=' + PeopleMedia.Profile.EncodedMemberId);
                            }
                        }
                        if (!PeopleMedia.Profile.IsSelfProfile) {
                            PeopleMedia.Profile.wireUpPhotos();
                        }
                        PeopleMedia.Profile.PhotosLoaded = true;

                    } else if (response.redirect) {
                        location.href = response.redirect;
                    }
                }
            });
        } else {
            PeopleMedia.Profile.ReloadAds();
        }

    };

    this.wireUpPhotos = function () {
        $jq('.photogallerylikephoto a').not('.button_style').click(function () { $jq('[data-comment-photo-id]').hide(); });
        $jq('#photoscontentarea').find('.photogalleryarearepeat').mouseenter(function () {
            var likePhoto = $jq(this).find('[data-like-photo-id]');
            if (likePhoto.length > 0) {
                $jq(this).find('[data-like-photo-id]').show();
            } else {
                $jq(this).find('[data-liked-photo-id]').show();
            }
        }).mouseleave(function () {
            $jq(this).find('[data-like-photo-id]').hide();
            $jq(this).find('[data-liked-photo-id]').hide();
        });
        $jq('[data-like-photo-id]').click(PeopleMedia.Profile.likePhoto);
        $jq(".PhotoLikeTextArea").focus(function () {
            if ($jq(this).val() == "What do you like about this photo?") {
                $jq(this).val('');
            }
            PeopleMedia.Profile.LimitPhotoComment();
        });
        $jq('.PhotoLikeTextArea').blur(function () {
            if ($jq(this).val() == "") {
                $jq(this).val('What do you like about this photo?');
            }
        });
        $jq('[data-liked-photo-id]').mouseenter(function () {
            var mediaId = $jq(this).attr('data-liked-photo-id');
            PeopleMedia.Profile.ShowPhotoComment(mediaId);
        });

    };

    this.ShowPhotoComment = function (mediaId) {
        if (mediaId) {
            $jq('[data-comment-photo-id]').not('[data-comment-photo-id=' + mediaId + ']').hide();
            var container = $jq('[data-comment-photo-id=' + mediaId + ']');
            container.show();
            container.find('a.button_style').unbind('click').bind('click', function () { PeopleMedia.Profile.commentPhoto(mediaId); });
        }
    };
    this.messageFocus = function () {
        $jq('.ProfileWriteMessageTextArea').focus();
        $jq('html, body').animate({
            scrollTop: 0
        }, 150);
    };
    this.loadHistory = function () {
        PeopleMedia.Profile.showTabHistory();
        if (!PeopleMedia.Profile.HistoryLoaded) {
            $jq.ajax({
                type: 'POST',
                url: PeopleMedia.Profile.Actions.GetInteractionUrl,
                data: { EncodedMemberId: PeopleMedia.Profile.EncodedMemberId },
                success: function (response) {
                    PeopleMedia.Profile.ReloadAds();
                    if (response.status == "Success") {
                        $jq('#ourhistorycontentarea').empty().html(response.html);
                        PeopleMedia.Profile.HistoryLoaded = true;
                    } else if (response.redirect) {
                        location.href = response.redirect;
                    }
                }
            });
        } else {
            PeopleMedia.Profile.ReloadAds();
        }


    };
    this.showError = function (message) {
        PeopleMedia.Popups.ShowGenericMessage(message);
    };
    this.handleError = function (response) {
        if (response.redirect) {
            location.href = response.redirect;
        } else if (response.message) {
            PeopleMedia.Profile.showError(response.message);
        }
    };
    this.showBdayOverLay = false;
    this.birthdayFlirtSent = false;
    this.sendBirthdayFlirt = function () {
        var url = PeopleMedia.Profile.Actions.SendBirthdayFlirtUrl;
        if (PeopleMedia.Profile.birthdayFlirtSent) {
            PeopleMedia.Profile.showError('You already sent a birthday flirt!');
        } else {
            $jq('#SendBirthdayFlirtText a').attr('href', 'javascript:;');
            //do we want to load bday flirt overlay? should be true/false
            PeopleMedia.Profile.showBdayOverLay = $jq('#showBdayOverlay').html();
            $jq('#profileoverlaybirthday').fadeOut(2500, function () {
                $jq('#SendBirthdayFlirtText').html('Wished ' + PeopleMedia.Profile.HimHerText + ' a<br />happy birthday!');
                $jq('#profileoverlaybirthday').fadeIn(2500);
            });
            $jq.ajax({
                type: 'POST',
                url: url,
                data: { EncodedMemberId: PeopleMedia.Profile.EncodedMemberId, FeatureName: PeopleMedia.Profile.FeatureName.Profile },
                success: function (response) {
                    if (response.status == "Success") {
                        if (PeopleMedia.Profile.showBdayOverLay == true || PeopleMedia.Profile.showBdayOverLay == 'True' || PeopleMedia.Profile.showBdayOverLay == '1') {
                            PeopleMedia.Profile.flirtSentPopup(true);
                        }
                    } else {
                        PeopleMedia.Profile.handleError(response);
                    }
                }
            });
        }
    };
    var lastToggle = null;
    this.toggleFavorite = function (addToFavs) {
        if (lastToggle && lastToggle.getTime() > ((new Date()).getTime() - 1000))
            return;
        lastToggle = new Date();
        var url = null;
        if (addToFavs) {
            $jq('.SaveToFavorites').hide();
            $jq('.RemoveFromFavorites').show();
            url = PeopleMedia.Profile.Actions.AddFavoriteUrl;
        } else {
            $jq('.RemoveFromFavorites').hide();
            $jq('.SaveToFavorites').show();
            url = PeopleMedia.Profile.Actions.RemoveFavoriteUrl;
        }
        $jq.ajax({
            type: 'POST',
            url: url,
            dataType: "json",
            data: { EncodedMemberId: PeopleMedia.Profile.EncodedMemberId, FeatureName: PeopleMedia.Profile.FeatureName.Profile },
            success: function (response) {
                if (response.status == "Success") {
                } else {
                    PeopleMedia.Profile.handleError(response);
                }
            }
        });
        return false;
    };

    this.likePhoto = function () {
        PeopleMedia.Profile.likePhotoById($jq(this).attr('data-like-photo-id'), false);
    };
    this.likePhotoById = function (mediaId, isZoom) {
        $jq.each(PeopleMedia.Profile.Photos, function (idx, val) { if (val.MediaId == mediaId) { val.Liked = true; } });
        if (!isZoom) {
            PeopleMedia.Profile.ShowPhotoComment(mediaId);
        } else {
        }
        $jq('[data-like-photo-id=' + mediaId + ']').remove();

        $jq.ajax({
            type: 'POST',
            url: PeopleMedia.Profile.Actions.LikePhotoUrl,
            data: {
                EncodedMemberId: PeopleMedia.Profile.EncodedMemberId,
                ObjectId: mediaId,
                FeatureName: isZoom ? PeopleMedia.Profile.FeatureName.ProfilePhotoZoom : PeopleMedia.Profile.FeatureName.ProfilePhotoTab
            },
            success: function (response) {
                if (response.status == "Success") {
                } else {
                    PeopleMedia.Profile.handleError(response);
                }
            }
        });

    };
    this.commentPhotoComplete = function (mediaId) {
        $jq('#ProfileCommentedPhoto' + mediaId).hide();
        $jq('[data-comment-photo-id=' + mediaId + ']').hide();
        $jq('#ProfileCommentedPhotoFull').hide();
    };
    var lastMessageSent = null;
    this.commentPhoto = function (mediaId, isZoom) {
        if (lastMessageSent && lastMessageSent.getTime() > ((new Date()).getTime() - 3000))
            return;
        lastMessageSent = new Date();
        var message = '';
        if (isZoom) {
            message = $jq('#SendFullCommentTextArea').val();
            $jq('#SendFullCommentTextArea').val('What do you like about this photo?');

        } else {
            message = $jq('#PhotoLikeTextArea' + mediaId).val();
            $jq('#PhotoLikeTextArea' + mediaId).val('What do you like about this photo?');
        }
        if (message != '' && message != 'What do you like about this photo?') {
            if (isZoom) {
                $jq('#ProfileCommentedPhotoFull').show();
            }
            else {
                $jq('#ProfileCommentedPhoto' + mediaId).show();
            }

            setTimeout('PeopleMedia.Profile.commentPhotoComplete(' + mediaId + ');', 3000);
            $jq.ajax({
                type: 'POST',
                url: PeopleMedia.Profile.Actions.CommentPhotoUrl + location.search,
                data: {
                    EncodedMemberId: PeopleMedia.Profile.EncodedMemberId,
                    ObjectId: mediaId,
                    Message: message,
                    UPN: PeopleMedia.Profile.SendCommentUPN,
                    FromPage: '&from=Profile',
                    FeatureName: isZoom ? PeopleMedia.Profile.FeatureName.ProfilePhotoZoom : PeopleMedia.Profile.FeatureName.ProfilePhotoTab
                },
                success: function (response) {
                    if (response.status == "Success") {
                    } else {
                        PeopleMedia.Profile.handleError(response);
                    }
                }
            });
        }
        else {
            PeopleMedia.Profile.showError("Please enter a comment!");
        }
    };
    this.sendMessage = function () {

        if (lastMessageSent && lastMessageSent.getTime() > ((new Date()).getTime() - 3000)) {
            $jq('#SendMessageButtonLink').one('click', PeopleMedia.Profile.sendMessage);
            return;
        }
            
        $jq('#SendMessageButtonLink').addClass('buttonunavailable');
        lastMessageSent = new Date();
        var message = $jq('#ProfileInlineMessage').val();
        var fromPage = location.search + '&from=Profile';
        if (PeopleMedia.Profile.IsTodaysMatch) {
            fromPage = fromPage + '&back=TodaysMatches&backparam=' + PeopleMedia.Profile.TodaysMatchCurrent;
        }
        if (message && message != 'Write Message...' && message != '' && (message != PeopleMedia.Profile.CommonalityMessage)
                && message != "Say Hello...") {
            $jq('#LoadingResultsDiv').show();
            $jq.ajax({
                type: 'POST',
                dataType: "json",
                url: PeopleMedia.Profile.Actions.SendMessageUrl,
                data: {
                    EncodedMemberId: PeopleMedia.Profile.EncodedMemberId,
                    Message: message,
                    UPN: PeopleMedia.Profile.SendMessageUPN,
                    FromPage: fromPage,
                    FeatureName: PeopleMedia.Profile.FeatureName.Profile,
                    SkipCSSVerif: 'HTMLEditor'
                },
                success: function (response) {
                    if (response.status == "Success") {
                        location.href = response.redirect;
                    } else {
                        PeopleMedia.Profile.handleError(response);
                    }
                }
                , complete: function (response) {
                    $jq('#SendMessageButtonLink').one('click', PeopleMedia.Profile.sendMessage);
                }
            });
            
        }
        else {
            PeopleMedia.Profile.showError("Write a message now to " + PeopleMedia.Profile.UserName + " then click send.");
            $jq('#SendMessageButtonLink').one('click', PeopleMedia.Profile.sendMessage);
            $jq('#SendMessageButtonLink').removeClass('buttonunavailable');
        }
        
    };

    this.showZodiacPopUp = function (encMemberId, param, search, start, back, backParam) {
        $jq.ajax({
            type: 'GET',
            url: PeopleMedia.Profile.Actions.AstrologerCompatabilityUrl,
            data: {
                encMemberId: encMemberId,
                paramAstrologer: param,
                search: search,
                start: start,
                back: back,
                backParam: backParam
            },
            success: function (response) {
                if (response.status == "Success") {
                    $jq('#astrologerContent').empty().html(response.html);
                    $jq('#astrologerContent').show();

                } else if (response.redirect) {
                    location.href = response.redirect;
                }
            }
        });
    };

    this.SendImInterestedFlirt = function () {
        if (PeopleMedia.Profile.IsTodaysMatch) {
            //location.href = '/v3/features/oneclickflirt?&Flirt=8&Profile=' + PeopleMedia.Profile.EncodedMemberId + '&back=TodaysMatches&hash=tab=about&featureName=' + PeopleMedia.Profile.FeatureName.TodaysMatch + '&backparam=' + PeopleMedia.Profile.TodaysMatchCurrent;
        }
        else {
            //location.href = '/v3/features/oneclickflirt?&Flirt=8&Profile=' + PeopleMedia.Profile.EncodedMemberId + '&back=Profile&hash=tab=about&featureName=' + PeopleMedia.Profile.FeatureName.Profile + '&backparam=' + PeopleMedia.Profile.EncodedMemberId;
        }
    };

    this.showTabAbout = function () {
        $jq("#profileaboutbtn").removeClass("profiletaboff").addClass("profiletabon");
        $jq("#profilephotosbtn").removeClass("profiletabon").addClass("profiletaboff");
        $jq("#profileourhistorybtn").removeClass("profiletabon").addClass("profiletaboff");
        $jq("#profilephotosarea").hide();
        $jq("#profileourhistoryarea").hide();
        $jq("#profileaboutarea").show();
        PeopleMedia.Profile.ReloadAds();
    };


    this.showTabPhotos = function () {
        $jq("#profileaboutbtn").removeClass("profiletabon").addClass("profiletaboff");
        $jq("#profilephotosbtn").removeClass("profiletaboff").addClass("profiletabon");
        $jq("#profileourhistorybtn").removeClass("profiletabon").addClass("profiletaboff");
        $jq("#profileaboutarea").hide();
        $jq("#profileourhistoryarea").hide();
        $jq("#profilephotosarea").show();
    };

    this.showTabHistory = function () {
        $jq("#profileourhistorybtn").removeClass("profiletaboff").addClass("profiletabon");
        $jq("#profileaboutbtn").removeClass("profiletabon").addClass("profiletaboff");
        $jq("#profilephotosbtn").removeClass("profiletabon").addClass("profiletaboff");
        $jq("#profileaboutarea").hide();
        $jq("#profilephotosarea").hide();
        $jq("#profileourhistoryarea").show();
    };



    this.LimitPhotoComment = function () {
        $jq(".PhotoLikeTextArea").keyup(function () {
            var limit = PeopleMedia.Profile.MaximumMessageLength;
            var text = $jq(this).val();
            var chars = text.length;
            if (chars > limit) {
                var new_text = text.substr(0, limit);
                $jq(this).val(new_text);
            }
            var remain = limit - chars;
            if (remain <= 0) {
                PeopleMedia.Popups.LongMessage();
            }
        });
    };

    this.init = function () {
        if (PeopleMedia.Profile.IsSelfProfile != true) {
            $jq('.SaveToFavorites').click(function () { PeopleMedia.Profile.toggleFavorite(true); });
            if (PeopleMedia.Profile.Actions.RemoveFavoriteUrl) {
            $jq('.RemoveFromFavorites').click(function () { PeopleMedia.Profile.toggleFavorite(false); });
            }
            $jq('#SendBirthdayFlirtLink').click(PeopleMedia.Profile.sendBirthdayFlirt);
            $jq('#SendMessageButtonLink').one('click', PeopleMedia.Profile.sendMessage);
            $jq('#SendFlirtButtonLink').click(PeopleMedia.Profile.sendFlirt);
        }

        $jq('.aboutmeclick').click(function () {
            $jq('.aboutmeclick').removeClass("whoimlookingfornavon").addClass("whoimlookingfornavoff");
            $jq('.aboutmymatchclick').removeClass("whoimlookingfornavoff").addClass("whoimlookingfornavon");
            $jq("#AboutMe").show();
            $jq("#AboutMyMatch").hide();
        });

        $jq('.aboutmymatchclick').click(function () {
            $jq('.aboutmeclick').removeClass("whoimlookingfornavoff").addClass("whoimlookingfornavon");
            $jq('.aboutmymatchclick').removeClass("whoimlookingfornavon").addClass("whoimlookingfornavoff");
            $jq("#AboutMe").hide();
            $jq("#AboutMyMatch").show();
        });

        $jq('#FullPhotoImage').load(function () { $jq(this).fadeIn('fast'); });
        $jq('.ProfileWriteMessageTextArea').focus(function () {
            if ($jq(this).val() == "Write Message..."
                || (PeopleMedia.Profile.CommonalityMessage.length > 1 && $jq(this).val() == PeopleMedia.Profile.CommonalityMessage)
                || $jq(this).val() == "Say Hello..."
            ){
                $jq(this).val('');
            }
        });
        $jq('.ProfileWriteMessageTextArea').blur(function () {
            if ($jq(this).val() == "") {
                if (PeopleMedia.Profile.IsCommonalityEnabled == 'true') {
                    $jq(this).val("Say Hello...");
                }
                else {
                    $jq(this).val('Write Message...');
                }
            }
        });
        if ($jq.param.fragment() == undefined || $jq.param.fragment() == '') {
            $jq.bbq.pushState({ tab: 'about' });
        }
        PeopleMedia.Profile.InitializePhotoZoom();
        $jq(window).bind('hashchange', PeopleMedia.Profile.hashchange);
        $jq(window).trigger('hashchange');

        if ($jq('#prevnextprofile').length == 0)
            $jq('#columnright').css("margin-top", "18px");

        $jq("#todaysmatchmessagebody, #ProfileInlineMessage").keyup(function () {
            var limit = PeopleMedia.Profile.MaximumMessageLength;
            var text = $jq(this).val();
            var chars = text.length;
            if (chars > limit) {
                var new_text = text.substr(0, limit);
                $jq(this).val(new_text);
            }
            var remain = limit - chars;
            if (remain <= 0) {
                PeopleMedia.Popups.LongMessage();
            }
        });
        if (!PeopleMedia.Profile.IsSelfProfile) {
            $jq("#greetinglink2").click(function () {
                PeopleMedia.Profile.messageFocus();
            });
        }
        $jq("#divProfileAdditionalInfo, #divProfileSimilarProfiles").find("div.profilecontainertopbutton").click(function () {
            var $img;
            var $content;
            var contentId = $jq(this).attr("data-content-id");
            if (contentId) {
                $content = $jq("#" + contentId);
                if ($content != null && $content.length > 0) {
                    $img = $jq(this).find("img:first");
                    if ($content.is(":visible")) {
                        $img.attr("src", PeopleMedia.SiteImagePath + "/images/buttons/plusprofile.png");
                        $content.hide();
                    } else {
                        $img.attr("src", PeopleMedia.SiteImagePath + "/images/buttons/minusprofile.png");
                        $content.show();
                    }
                }
            }
        });
        setTimeout(function () {
            PeopleMedia.Profile.isInitialized = true;
        }, 1000);
    };
    this.ReloadAds = function () {
        if (PeopleMedia.Profile.isInitialized == true) {
            //PeopleMedia.ReloadAds();
        }
    };
    this.lastHash = { tab: 'about' };
    this.isInitialized = false;
    this.hashchange = function (event) {
        var state = $jq.bbq.getState();
        if (state == undefined || state.tab == undefined) {
            PeopleMedia.Profile.showTabAbout();
        }
        if (state.zoomPhoto != undefined && state.zoomPhoto != '') {
            PeopleMedia.Profile.loadPhotos();
            PeopleMedia.Profile.ShowZoomPhoto(state.zoomPhoto);
        } else {
            PeopleMedia.Profile.ShowMainContent();
            if (state.tab === 'photos') {
                PeopleMedia.Profile.loadPhotos();
            }
            else if (state.tab === 'about') {
                PeopleMedia.Profile.showTabAbout();
            }
            else if (state.tab == 'history') {
                PeopleMedia.Profile.loadHistory();
            }
            PeopleMedia.Profile.lastHash = state;

        }
    };
    this.ShowMainContent = function () {
        $jq('#profilecontenttop').show();
        $jq('#profilecontentmiddle').show();
        $jq('#profilecontentbottom').show();
        $jq('#backlink').show();
        $jq('#zoomPhoto').hide();

    };
    this.ShowZoomPhoto = function (index) {
        if (PeopleMedia.Profile.Photos == undefined || PeopleMedia.Profile.Photos == null || PeopleMedia.Profile.Photos.length <= 0) {
            PeopleMedia.Profile.ShowMainContent();
            return;
        }
        index = Number(index);
        $jq('#profilecontenttop').hide();
        $jq('#profilecontentmiddle').hide();
        $jq('#profilecontentbottom').hide();
        $jq('#backlink').hide();
        $jq('#zoomPhoto').show();
        var prevIndex = index <= 0 ? PeopleMedia.Profile.Photos.length - 1 : index - 1;
        var nextIndex = index >= PeopleMedia.Profile.Photos.length - 1 ? 0 : index + 1;
        $jq('.profilesolophotonav img.left').parent().attr('href', '#tab=photos&zoomPhoto=' + prevIndex);
        $jq('.profilesolophotonav img.right').parent().attr('href', '#tab=photos&zoomPhoto=' + nextIndex);
        var photo = PeopleMedia.Profile.Photos[index];
        var $image = $jq('#FullPhotoImage');
        if ($image.attr('src') != photo.FullSizeUrl) {
            $image.fadeOut('fast', function () {
                $image.attr('src', photo.FullSizeUrl);
                $image.parent().attr('href', '#tab=photos&zoomPhoto=' + nextIndex);
            });
        }
        if (photo.Caption && photo.Caption != '') {
            $jq('.profilesolophotocaption').html('<span>&#8220;</span>' + photo.Caption + '<span>&#8221;</span>');
        } else {
            $jq('.profilesolophotocaption').html('&nbsp;');
        }
        $jq('#ProfileCommentedPhotoFull').hide();
        $jq('.profilesolophotoimgcount').html((index + 1) + ' of ' + PeopleMedia.Profile.Photos.length);


        if (PeopleMedia.Profile.IsSelfProfile) {
            $jq('#ReportFullPhotoConcern').unbind();
            $jq('#SendFullCommentButton').unbind();
            $jq('#FullPhotoLikeButton').unbind();
            $jq('#SendFullCommentTextArea').hide();
            $jq('#SendFullCommentButton').hide();
            $jq('#FullPhotoLikeButton').show();
            $jq('#FullPhotoLikedButton').hide();
        } else {
            if (photo.Liked === true) {
                $jq('#FullPhotoLikedButton').show();
                $jq('#SendFullCommentTextArea').show();
                $jq('#SendFullCommentButton').show();
                $jq('#FullPhotoLikeButton').hide();
            } else {
                $jq('#SendFullCommentTextArea').hide();
                $jq('#SendFullCommentButton').hide();
                $jq('#FullPhotoLikeButton').show();
                $jq('#FullPhotoLikedButton').hide();
            }
            $jq('#FullPhotoLikeButton').unbind().click(function () {
                PeopleMedia.Profile.likePhotoById(photo.MediaId, true);
                $jq('#FullPhotoLikedButton').show();
                $jq('#SendFullCommentTextArea').show();
                $jq('#SendFullCommentButton').show();
                $jq('#FullPhotoLikeButton').hide();

            });
            $jq('#SendFullCommentButton').unbind().click(function () {
                PeopleMedia.Profile.commentPhoto(photo.MediaId, true);
            });

            $jq('#ReportFullPhotoConcern').unbind().click(function () {
                PeopleMedia.Popups.ReportConcern(PeopleMedia.Profile.EncodedMemberId, PeopleMedia.Profile.UserName, photo.MediaId);
                PeopleMedia.Profile.ReloadAds();
            });
        }
        PeopleMedia.Profile.RecordNextPhoto();
   
    };

    this.RecordNextPhoto = function () {
      
        var startTime = new Date().getTime();
        var url = FRONT_SITE_URL+'user/profile/RecordNextPhoto';
        var timeoutValue = 60000;
        $jq.ajax({
            type: "GET",
            url: url,
            data: {},
            dataType: "json",
            success: function (result) {
                PeopleMedia.Profile.ReloadAds();
            },
            error: function (jqXHR, textStatus, errorThrown) {
                if (errorThrown === 'timeout' || (jqXHR.readyState !== 0 && jqXHR.status !== 0)) {
                    var endTime = new Date().getTime();
                    var duration = (endTime - startTime);
                    // PeopleMedia.Popups.ShowGenericMessage(PeopleMedia.Popups.AjaxErrorMessage());
                    PeopleMedia.Logger.LogAjaxErrorXHR("Ajax request failure", url, { method: "PeopleMedia.Profile.RecordNextPhoto", duration: duration }, jqXHR, textStatus, errorThrown, function () {
                    });
                }
            },
            async: true,
            cache: false,
            timeout: timeoutValue,
            suppressErrors: true
        });
    };

    this.InitializePhotoZoom = function () {
        $jq('.ClosePhotoZoom').click(function () { $jq.bbq.removeState('zoomPhoto'); });

    };
};



